﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Bidder_CompanyConstract : System.Web.UI.Page,HZ.MBSM.BLL.TraDes
{
    string _strProjectIdConstract = "";
    public string _AreaIConstract = "";
    Int64 _TraCompnyContractAccountId;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {

            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
                _AreaIConstract = SysFun.ToTrim(_Account.AreaId);
                _TraCompnyContractAccountId = _Account.AccountId;
                _strProjectIdConstract = SysFun.IsSQL(Request.QueryString["ProjectId"]);
                showGridView();

            }
        }
    }

    public void showGridView()
    {
        int i = 0;
        string j = DropDownList1.SelectedValue.ToString();
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "PurchaseTable";
        dbPage.SelectFieldGroup = "UserCode_TB,CompanyName_TB,UserCode_PS,CompanyName_PS,AccountId_PS,AccountId_TB,AccountId_YY,HospitalName,UserCode_YY,ProjectId,print_state";                                       //要查询的表明
        //dbPage.SelectFieldGroup = fctFieldGroup();
        dbPage.SelectField = "UserCode_TB,CompanyName_TB,UserCode_PS,CompanyName_PS,AccountId_PS,AccountId_TB,AccountId_YY,HospitalName,UserCode_YY,ProjectId,print_state,Sum(PurchasePrice*Isnull(PlanPurNum,0)) AS SUMMoney";//要显示的字段
        //dbPage.SelectField = fctSelectField();
        dbPage.Key = "CompanyName_TB,CompanyName_PS,AccountId_PS,AccountId_TB,AccountId_YY,HospitalName,UserCode_YY,ProjectId";                                               //表的主键    
        //dbPage.Key = fctKey();
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);         //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "CompanyName_TB,CompanyName_PS,AccountId_PS,AccountId_TB,AccountId_YY,ProjectId,print_state";//排序字段
        //dbPage.OrderBy = fctOrderBy();

        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='right' cellpadding='2' cellspacing='1'>");
        strHtml.Append("<tr>");
        if (j == "2")
        {
            //strHtml.Append("<td width='10%'>中标人注册号</td>");
            //strHtml.Append("<td width='20%'>中标人名称</td>");
            strHtml.Append("<td width='10%'>医院注册号</td>");
            strHtml.Append("<td width='20%'>医院名称</td>");
            strHtml.Append("<td width='10%'>配送企业注册号</td>");
            strHtml.Append("<td width='20%'>配送企业名称</td>");
            //strHtml.Append("<td  width='10%'>打印合同</td>");
            strHtml.Append("<td  width='10%'>打印合同附表</td>");
            strHtml.Append("<td width='10%'>总金额</td>");
        }
        else if (j == "3")
        {
            //strHtml.Append("<td width='10%'>配送企业注册号</td>");
            //strHtml.Append("<td width='20%'>配送企业名称</td>");
            strHtml.Append("<td width='10%'>医院注册号</td>");
            strHtml.Append("<td width='20%'>医院名称</td>");
            strHtml.Append("<td width='10%'>中标人注册号</td>");
            strHtml.Append("<td width='20%'>中标人名称</td>");
            //strHtml.Append("<td  width='10%'>打印合同</td>");
            strHtml.Append("<td  width='10%'>打印合同附表</td>");
            strHtml.Append("<td width='10%'>总金额</td>");
        }
        //else if (j == "4")
        //{
        //    strHtml.Append("<td width='10%'>生产企业注册号</td>");
        //    strHtml.Append("<td width='30%'>生产企业名称</td>");
        //    strHtml.Append("<td width='10%'>医院注册号</td>");
        //    strHtml.Append("<td width='30%'>医院名称</td>");

          // strHtml.Append("<td width='10%'>总金额</td>");
        //}
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReaderGroup(60);

        while (dr.Read())
        {
            if (i == 0)
            {
                strHtml.Append("<tr class='table_td'>");
                i++;
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
                i--;
            }
            if (j == "2")//中标人
            {
                //strHtml.Append("<td> " + dr["UserCode_TB"].ToString() + " </td>");
                //strHtml.Append("<td><a href='../agency/company_xq.aspx?&Accountid_PS=" + dr["AccountId_TB"].ToString() + "' target='_blank'>" + dr["CompanyName_TB"].ToString() + "</a></td>");
                strHtml.Append("<td>" + dr["UserCode_YY"].ToString() + "</td>");
                strHtml.Append("<td>" + dr["HospitalName"].ToString() + "</td>");
                strHtml.Append("<td>" + dr["UserCode_PS"].ToString() + " </td>");
                strHtml.Append("<td>" + dr["CompanyName_PS"].ToString() + "</td>");
                //strHtml.Append("<td width='10%'><a href='../Hospital/Print.aspx?CompanyName_TB=" + dr["CompanyName_TB"].ToString() + "&AccountId_TB=" + dr["AccountId_TB"].ToString() + "&AccountId_PS=" + dr["AccountId_PS"].ToString() + "&AccountId_YY=" + dr["AccountId_YY"].ToString() + "&CompanyName_PS=" + dr["CompanyName_PS"].ToString() + "&Projectid=" + _strProjectIdConstract + "' target='_blank' >打印合同</a>");
        
                strHtml.Append("<td width='10%'><a href='../Hospital/PrintPurList.aspx?AccountId_TB=" + dr["AccountId_TB"].ToString() + "&Accountid_PS=" + dr["AccountId_PS"].ToString() + "&ProjectId=" + _strProjectIdConstract + "&AccountId_YY=" + dr["AccountId_YY"].ToString() + "&Id=1' target='_blank'><font color= red>打印合同附表</font></a>");
                strHtml.Append("<td>" + dr["SUMMoney"].ToString() + "</td>");
            }
            else if (j == "3")//配送企业
            {
                //strHtml.Append("<td>" + dr["UserCode_PS"].ToString() + " </td>");
                //strHtml.Append("<td><a href='../agency/company_xq.aspx?&Accountid_PS=" + dr["AccountId_PS"].ToString() + "' target='blank' target='_blank'>" + dr["CompanyName_PS"].ToString() + "</a></td>");
                strHtml.Append("<td>" + dr["UserCode_YY"].ToString() + "</td>");
                strHtml.Append("<td>" + dr["HospitalName"].ToString() + "</td>");
                strHtml.Append("<td> " + dr["UserCode_TB"].ToString() + "</td>");
                strHtml.Append("<td>" + dr["CompanyName_TB"].ToString() + "</td>");
               // strHtml.Append("<td width='10%'><a href='../Hospital/Print.aspx?CompanyName_TB=" + dr["CompanyName_TB"].ToString() + "&AccountId_TB=" + dr["AccountId_TB"].ToString() + "&AccountId_PS=" + dr["AccountId_PS"].ToString() + "&AccountId_YY=" + dr["AccountId_YY"].ToString() + "&CompanyName_PS=" + dr["CompanyName_PS"].ToString() + "&Projectid=" + _strProjectIdConstract + "' target='_blank' >打印合同</a>");

                strHtml.Append("<td width='10%'><a href='../Hospital/PrintPurList.aspx?AccountId_TB=" + dr["AccountId_TB"].ToString() + "&Accountid_PS=" + dr["AccountId_PS"].ToString() + "&ProjectId=" + _strProjectIdConstract + "&AccountId_YY=" + dr["AccountId_YY"].ToString() + "&Id=2' target='_blank'><font color= red>打印合同附表</font></a>");
                strHtml.Append("<td>" + dr["SUMMoney"].ToString() + "</td>");
            }
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }

    public string fctConditions()
    {
        String _strfctConditionsSel = DropDownList1.SelectedValue.ToString();
        String _strTemp = "";
        if (_strfctConditionsSel.Equals("2"))//中标人
        {
            _strTemp = " State='正常采购' and ProjectId=" + _strProjectIdConstract + " And AccountId_TB=" + _TraCompnyContractAccountId.ToString() + "And";
        }
        else if (_strfctConditionsSel.Equals("3"))//配送企业
        {
            _strTemp = " State='正常采购' and ProjectId=" + _strProjectIdConstract + " And AccountId_PS=" + _TraCompnyContractAccountId.ToString() + "And";
        }
   

        //投标人名称
        //string _strCompanyName_TB = this.txtCompanyName_TB.Text.ToString();
        //if (_strCompanyName_TB != "")
        //{
        //    _strTemp += " CompanyName_TB like '%" + _strCompanyName_TB + "%' and";
        //}
        //投标人编码
        //string _strUserCode_TB = this.txtUserCode_TB.Text.ToString();
        //if (_strUserCode_TB != "")
        //{
        //    _strTemp += " UserCode_TB like '%" + _strUserCode_TB + "%' and";
        //}

        //配送企业名称
        //string _strCompanyName_PS = this.txtCompanyName_PS.Text.ToString();
        //if (_strCompanyName_PS != "")
        //{
        //    _strTemp += " CompanyName_PS like '%" + _strCompanyName_PS + "%' and";
        //}

        //配送企业编码
        //string _strUserCode_PS = this.txtUserCode_PS.Text.ToString();
        //if (_strUserCode_PS != "")
        //{
        //    _strTemp += " UserCode_PS like '%" + _strUserCode_PS + "%' and";
        //}
        //医院名称
        string _strHospitalName = this.txtHospitalName.Text.ToString();
        if (_strHospitalName != "")
        {
            _strTemp += "  HospitalName like '%" + _strHospitalName + "%' and";
        }

        //医院编码
        string _strUserCode_YY = this.txtUserCode_YY.Text.ToString();
        if (_strUserCode_YY != "")
        {
            _strTemp += " UserCode_YY like '%" + _strUserCode_YY + "%' and";
        }
        //生产企业名称
        //string _strCompanyName_sc = this.txtCompanyName_sc.Text.ToString();
        //if (_strCompanyName_sc != "")
        //{
        //    _strTemp += " CompanyName_sc  like '%" + _strCompanyName_sc + "%' and";
        //}
        //生产企业编码
        //string _strUserCode_SC = this.txtUserCode_SC.Text.ToString();
        //if (_strUserCode_SC != "")
        //{
        //    _strTemp += " UserCode_SC like '%" + _strUserCode_SC + "%' and";
        //}
        //地区
        //_strTemp += SysFun.AreaIdWhere(_AreaIdLook);

        if (_strTemp != "")
        {
            _strTemp = "  " + _strTemp.Substring(0, _strTemp.Length - 3);
        }

        return _strTemp;
    }

    #region TraDes 成员

    public string Name
    {
        get { return "企业查看合同"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "查看合同"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
            return _AccountType;
        }
    }

    #endregion
}
